<?php

namespace app\system\model;

use think\Model;

class SysMenuModel extends Model
{
    protected $table = "sys_menu";
    protected $pk = "menu_id";

    protected $field = [
        "menu_id",          // 菜单id
        "pid",              // 父id
        "m_name",           // 菜单名字
        "icon",             // 图标
        "mca_url",          // 模块/控制器/方法
        "sort",             // 排序
    ];

    public function getMenuListByPid($pid)
    {
        $menuList = $this->where(["pid" => $pid])->select();
        return $menuList;
    }

    public function getMenuById($menu_id){
        $menu = $this->where(["menu_id"=>$menu_id])->find();
        return $menu;
    }

    public function getMenuList()
    {
        $menuList = $this->order(["sort" => "asc"])->select()->toArray();
        return $menuList;
    }
    
    public function addMenuData($data){
        $addResult = $this->allowField(true)->save($data);
        return $addResult;
    }

    public function updMenuData($data,$menu_id){
        $updResult = $this->allowField(true)->force(true)->save($data,["menu_id"=>$menu_id]);
        return $updResult;
    }

    public function delMenu($menu_id){
        $delResult = $this->where(["menu_id"=>$menu_id])->delete();
        return $delResult;
    }
}
